//
//  ZhuantiVC.m
//  AStage_shougongke
//
//  Created by 赵磊 on 16/1/20.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ZhuantiVC.h"
#import "aStageHeader.pch"
@interface ZhuantiVC ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSArray *dataArr;
@end

@implementation ZhuantiVC
// 页面即将出现 将tabBar显示
- (void)viewWillAppear:(BOOL)animated
{
    // tabBar显示
    self.tabBarController.tabBar.hidden = YES;
}
// 页面即将消失 将tabBar隐藏
- (void)viewWillDisappear:(BOOL)animated
{
    // tabBar隐藏
    self.tabBarController.tabBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"专题";
    // 隐藏push自动生成的返回按钮
    [self.navigationItem setHidesBackButton:YES];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerClass:[ZhuantiTableViewCell class] forCellReuseIdentifier:@"cell"];
    _tableView.separatorStyle = NO;
    [self.view addSubview:_tableView];
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT - 50, WIDTH, 50)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    // 创建返回的button
    UIButton * fanhui = [UIButton buttonWithType:UIButtonTypeCustom];
    [fanhui setImage:[UIImage imageNamed:@"fanhui@2x"] forState:UIControlStateNormal];
    fanhui.frame = CGRectMake(0, 0, 50, 50);
    [fanhui addTarget:self action:@selector(fanhui) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:fanhui];
    [_tableView release];
    [self dataHandler];
    [view release];
}
- (void)dataHandler
{
    [AFNModel GETWithURL:@"http://m.shougongke.com/index.php?&c=Course&a=topic&vid=15" completion:^(id result) {
        NSArray *arrTemp = [NSArray array];
        arrTemp = result[@"data"][@"list"];
        self.dataArr = [ZhuantiModel modelHandlerWithArray:arrTemp];
        [_tableView reloadData];
    }];
}
// 返回
- (void)fanhui
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return WIDTH / 2 + 50;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ZhuantiTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    ZhuantiModel *m = _dataArr[indexPath.row];
    NSArray *arr = m.pic;
    cell.title.text = m.subject;
    [cell.bigImg sd_setImageWithURL:[NSURL URLWithString:arr[0]]];
    [cell.leftUpImg sd_setImageWithURL:[NSURL URLWithString:arr[1]]];
    [cell.rightUpImg sd_setImageWithURL:[NSURL URLWithString:arr[2]]];
    [cell.leftDownImg sd_setImageWithURL:[NSURL URLWithString:arr[3]]];
    [cell.rightDownImg sd_setImageWithURL:[NSURL URLWithString:arr[4]]];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ZtxqVC *zhuantixiangqingVC = [[ZtxqVC alloc] init];
    ZhuantiModel *m = _dataArr[indexPath.row];
    // 将本页获得的点击网址赋值给将要进入页面的属性
    zhuantixiangqingVC.zId = m.id;
    zhuantixiangqingVC.timu = m.subject;
    [self.navigationController pushViewController:zhuantixiangqingVC animated:YES];
    [zhuantixiangqingVC release];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
